package cn.hfatec.shms.web.members.userGrade.action;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;
import java.util.ArrayList;
import java.util.Arrays;
import javax.annotation.Resource;


import cn.hfatec.JsonResponse;
import cn.hfatec.Page;
import cn.hfatec.Table;
import cn.hfatec.constants.SysContant;
import cn.hfatec.freemarker.FreeMarkerUtil;
import cn.hfatec.shms.web.members.userGrade.model.UserGradeParams;
import cn.hfatec.shms.web.members.userGrade.model.UserGrade;
import cn.hfatec.shms.web.members.userGrade.service.UserGradeService;
import cn.hfatec.shms.base.ShmsBaseAction;
import org.springframework.ui.Model;
import javax.validation.Valid;
import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;



/**
 *
 * @author hfatec codegen
 * @version 1.0
 *
 * the JAVA code is generate by middlegen
 *
 */
@Controller
@RequestMapping("/members/userGrade")
public class UserGradeAction extends ShmsBaseAction {

    //服务层
    @Resource(name = "UserGradeService")
    private UserGradeService userGradeService;


    /**
     *
     * 查询列表
     *
     */
    @RequestMapping("/list")
    public String list(UserGradeParams userGradeParams,  Model model) {

        List table = userGradeService.queryUserGradeTable(userGradeParams);
        model.addAttribute("userGradesTable", table);


        model.addAttribute("userGradeParams", userGradeParams);
        return "/members/userGrade/list";
    }

    /**
     *
     * 异步查询列表
     *
     */
    @RequestMapping("/ajaxList")
    @ResponseBody
    public String ajaxList(UserGradeParams userGradeParams,  Model model) {
        try {
            list(userGradeParams,  model);
            return new JsonResponse<Map>(JsonResponse.RETURN_SUCCESS, "", FreeMarkerUtil.render("/members/userGrade/table", model)).toString();
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
        return JsonResponse.error;
    }

    /**
     *
     * 跳转到新增页
     *
     */
    @RequestMapping("/goAdd")
    @ResponseBody
    public String goAdd(Model model) {
        try {
            UserGrade userGrade = new UserGrade();
            model.addAttribute("userGrade", userGrade);
            return new JsonResponse<Map>(JsonResponse.RETURN_SUCCESS, "", FreeMarkerUtil.render("/members/userGrade/form", model)).toString();

        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
        return JsonResponse.error;
    }


}
